using System.Data.OleDb;
using System.Windows.Forms;

namespace DAO
{
    public class MyConnection
    {
        private static readonly string Path = Application.StartupPath;
        public static OleDbConnection ConnectionData()
        {
            string projectPath = GetConnectionString();
            string cnStr = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source ="+projectPath+"dulieu.mdb";
            OleDbConnection cn = new OleDbConnection(cnStr);
            cn.Open();
            return cn;
        }
        public static string GetConnectionString()
        {
            string projectPath = Path.Replace("\\Bin", "\\Dulieu\\");
            //string projectPath = "\\bin\\Debug\\";
            //string projectPath = Application.StartupPath.Replace("\\bin\\Debug", "\\Dulieu\\");
            
            return projectPath;
        }
        public enum Loaihoadon
        {
            Hoadonban=0,
            Hoadonmua=1
        }

        public enum Hinhthucban
        {
            Lieu=0,
            Mon=1,
            Toa=2
        }
        public static int GetnewId(OleDbTransaction transaction)
        {
            string sqlString1 = "SELECT @@IDENTITY AS NewID";
            OleDbCommand cmd = new OleDbCommand();
            if(transaction != null)
            {
                cmd.Connection = transaction.Connection;
                cmd.Transaction = transaction;
            }else
            {
                cmd.Connection = ConnectionData();
            }
            
            cmd.CommandText = sqlString1;
            return (int)cmd.ExecuteScalar();
        }
    }
}
